package Servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import Beans.OrderForm;
import DaosImpl.ClientDaoImpl;

/**
 * Servlet implementation class OutHomeServlet
 */
@WebServlet("/OutHomeServlet")
public class OutHomeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OutHomeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		ArrayList<OrderForm> cancelList = new ArrayList<OrderForm>();
		try{
			ClientDaoImpl insert = new ClientDaoImpl();
			String outdate = request.getParameter("outdate");
			String roomid = request.getParameter("roomid");
			String ofId = request.getParameter("ofId");
			outdate = java.net.URLDecoder.decode(outdate,"UTF-8");
			roomid = java.net.URLDecoder.decode(roomid,"UTF-8");
			ofId = java.net.URLDecoder.decode(ofId,"UTF-8");
			System.out.println(roomid);
			String sql1 = "UPDATE Room SET r_status='1' WHERE r_id='"+roomid+"';";
			//String sql2 = "UPDATE Order_Form SET of_leavedate='"+outdate+"' WHERE of_id='"+ofId+"';";
			String sql2 = "UPDATE Order_Form SET of_leavedate='"+outdate+"' from Order_Form,Open_Room where Order_Form.of_id=Open_Room.of_id and r_id='"+roomid+"' and of_leavedate is null;";
			insert.insertInfo(sql1);
			insert.insertInfo(sql2);
			response.sendRedirect("/HotelSystem/cancelOrder.jsp");
			
		}catch(Exception e){
			
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
